<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
  
        .iSlider-container {
            width: 100%;
            display: flex;
            flex-direction: column;
            position: relative;
        }

        .img-container {
            overflow: hidden;
            order: 1;
        }

        .iSlider-container .img-container .img-item {
            float: left;
            width: 100%;
        }

        .iSlider-nav {
            margin: .5rem 0;
            cursor: pointer;
            position: relative;
            order: 2;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 15;
            display: -ms-flexbox;
            display: flex;
            -ms-flex-pack: center;
            justify-content: center;
            padding-left: 0;
            margin-right: 15%;
            margin-left: 15%;
            list-style: none;
            background-color: rgba(0, 0, 0, .5);
        }

        .iSlider-nav li {
            box-sizing: content-box;
            -ms-flex: 0 1 auto;
            flex: 0 1 auto;
            width: 30px;
            height: 3px;
            margin-right: 3px;
            margin-left: 3px;
            text-indent: -999px;
            cursor: pointer;
            background-color: #fff;
            background-clip: padding-box;
            border-top: 10px solid transparent;
            border-bottom: 10px solid transparent;
            opacity: .5;
            transition: opacity .6s ease;
        }

        .iSlider-nav .active {
            opacity: 1;
        }

        .img-item {
            display: none;
            position: relative;
            text-align: center;
            margin-right: -100%;
            backface-visibility: hidden;
            transition: -webkit-transform .6s ease-in-out;
            transition: transform .6s ease-in-out;
            transition: transform .6s ease-in-out, -webkit-transform .6s ease-in-out
        }

        .img-item-left {
            -webkit-transform: translateX(-100%);
            transform: translateX(-100%)
        }

        .img-item-right {
            -webkit-transform: translateX(100%);
            transform: translateX(100%)
        }

        .img-item a img {
            width: 360px;
            height: 202px;
        }

        .img-item a p {
            line-height: 1.4;
            position: absolute;
            bottom: 0;
            width: 100%;
            margin-bottom: 0;
            padding: .8rem 1.5rem;
            color: #fff;
            background-color: rgba(0, 0, 0, .5);
        }

        .active {
            display: block;
            z-index: 10;
            background-color: rgb(20, 190, 220);
        }
    </style>
</head>

<body>
    <div class="iSlider-container">
        <ol class="iSlider-nav" id="iSlider_nav">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ol>
        <div class="img-container" id="img_container">
            <div class="img-item active">
                <a href="">
                    <img src="static/img/ball.jpg" alt="">
                    <p class="img-item-detail">hello world!</p>
                </a>
            </div>
            <div class="img-item">
                <a href="">
                    <img src="static/img/cake.jpg" alt="">
                    <p class="img-item-detail">hello world!</p>
                </a>
            </div>
            <div class="img-item">
                <a href="">
                    <img src="static/img/coco.jpg" alt="">
                    <p class="img-item-detail">hello world!</p>
                </a>
            </div>
            <div class="img-item">
                <a href="">
                    <img src="static/img/die.jpg" alt="">
                    <p class="img-item-detail">hello world!</p>
                </a>
            </div>
            <div class="img-item">
                <a href="">
                    <img src="static/img/imooc.png" alt="">
                    <p class="img-item-detail">hello world!</p>
                </a>
            </div>
        </div>
    </div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>

    var isActive = false
    var activeIndex = 0
    var itemSize
    var moveInterval
    var movePeriod=1000
    var direction='right'
    var intervalTime=5000

    $(document).ready(function () {
        itemSize = $('#img_container').children('.img-item').length
        startInterval(intervalTime)
    })

    function startInterval(period){
        moveInterval=setInterval("move('right')", period)
    }

    function move(direction) {

        var moveToIndex
        var reverseDirection;

        if (direction === 'left') {
            reverseDirection = 'right'

            if (activeIndex === 0) {
                moveToIndex = itemSize - 1
            } else {
                moveToIndex = activeIndex - 1
            }

        } else if (direction === 'right') {
            reverseDirection = 'left'

            if (activeIndex === itemSize - 1) {
                moveToIndex = 0
            } else {
                moveToIndex = activeIndex + 1
            }
        }

        var moveToObj = $('#img_container').children('.img-item').eq(moveToIndex)
        moveToObj.addClass('img-item-' + reverseDirection)
        moveToObj.addClass('active')
        // moveToObj.addClass('img-item-' + direction)


        var activeObj = $('#img_container').children('.img-item').eq(activeIndex)
        palyAnimate(direction, activeObj, moveToObj,movePeriod)
        console.log('move left: activeIndex ' + activeIndex + ' nextIndex: ' + moveToIndex + ' obj:' + activeObj)
        activeIndex = moveToIndex
    }


    function palyAnimate(direction, activeObj, moveToObj,duration) {
        var reverseDirection;
        if (direction === 'left') {
            reverseDirection = 'right'
        } else if (direction === 'right') {
            reverseDirection = 'left'
        }
        setTimeout(function () {
            //左移显示的ActiveObj
            activeObj.addClass('img-item-' + direction).delay(duration).queue(function () {
                //再把ActiveObj移回原位和隐藏
                activeObj.removeClass('img-item-' + direction)
                activeObj.removeClass('active')
                activeObj.dequeue()
                console.log('queue start')
            })
            //从translateX 100%移回原位
            moveToObj.removeClass('img-item-' + reverseDirection)
            moveToObj.removeClass('img-item-' + direction)

            moveNavigator(activeIndex)
            console.log('paly animate ' + direction)
        }, duration)
    }

    function moveNavigator(activeIndex) {
        var activeObj = $('#iSlider_nav').children('li').eq(activeIndex)
        activeObj.addClass('active').siblings().removeClass('active')
    }

    function moveToIndex(toIndex){
        clearInterval(moveInterval)
       
    }

</script>

</html>